<template>
    <div class="history">
        <header>
            <div class="back" @click="back">
                <van-icon name="arrow-left" size="32" color="#5a5a5a" />
            </div>
            <div class="text">历史记录</div>
        </header>
        <main>
            <div class="wrap">
                <div class="content" v-for="(i, index) in dataArr" :key="index">
                    <div class="img" :style="{ backgroundImage: `url(${i.src})` }"></div>
                    <div class="c-text">
                        <div class="title van-ellipsis">{{ i.name }}</div>
                        <div class="select van-ellipsis">{{ i.select }}</div>
                        <div class="num van-ellipsis">数量{{ i.num }}</div>
                        <div class="price van-ellipsis">
                            总价<span>{{ (i.price * i.num).toFixed(2) }}</span>
                        </div>
                    </div>
                </div>
            </div>
        </main>
    </div>
</template>

<script>
export default {
    props: ["account"],
    data() {
        return {
            dataArr: [],
        };
    },
    methods: {
        back() {
            this.$router.go(-1);
        },
        allShopApi() {
            console.log(this.account);
            this.axios("http://127.0.0.1/getPurchaseRecord", {
                params: {
                    account: this.account,
                },
            }).then(({ data }) => {
                this.dataArr = data.data;
                console.log(data);
            });
        },
    },
    beforeRouteEnter(to, from, next) {
        next((vm) => {
            vm.allShopApi();
        });
    },
};
</script>

<style lang="scss" scoped>
.history {
    background-color: #fafafa;
    width: 100vw;
    min-height: 100vh;
}
header {
    background-color: #fff;
}
.back {
    width: 100vw;
    height: 2.625rem;
    padding: 0.3125rem 2vw;
    box-sizing: border-box;
}
.text {
    position: absolute;
    top: 0.6875rem;
    left: 50%;
    transform: translateX(-50%);
    font-size: 20px;
    color: #1ba784;
    font-weight: 600;
}
main {
    padding: 2vh 5vw;
    .content {
        margin-bottom: 2vh;
        width: 100%;
        height: 15vh;
        background-color: #fff;
        border-radius: 30px;
        padding: 2vh 5vw;
        box-sizing: border-box;
        display: flex;
        justify-content: space-between;
        .img {
            width: 35%;
            height: 100%;
            background-position: center;
            background-size: cover;
        }
        .c-text {
            width: 60%;
            height: 100%;
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            & > div {
                width: 100%;
                font-size: 18px;
            }
            .title {
                font-size: 24px;
                font-weight: 600;
            }
            .price {
                span {
                    color: red;
                    font-weight: 600;
                }
            }
        }
    }
}
</style>
